package com.raining.inningz.baseclass;



import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.TextView;

import com.raining.inningz.R;
import com.raining.inningz.database.DbManager;
import com.raining.inningz.database.dao.ActionCommentaryDao;
import com.raining.inningz.database.dao.BattingSummaryDao;
import com.raining.inningz.database.dao.BowlingSummaryDao;
import com.raining.inningz.database.dao.DaoSession;
import com.raining.inningz.database.dao.ExtrasSummaryDao;
import com.raining.inningz.database.dao.MatchDetailsDao;
import com.raining.inningz.database.dao.MatchInningsDao;
import com.raining.inningz.database.dao.MatchResultsDao;
import com.raining.inningz.database.dao.MatchesDao;
import com.raining.inningz.database.dao.PlayerDao;

import com.raining.inningz.database.dao.ScoreLineDao;
import com.raining.inningz.database.dao.ScoringTemplatesDao;
import com.raining.inningz.database.dao.SubscriptionsDao;
import com.raining.inningz.manager.SelectorManager;




public abstract  class BaseFragment extends Fragment {


public Intent intent;
	
	public Button btnLeft;
	public Button btnRight;
	public TextView title;
	
	public Resources resources;
	
	
	public Context context;
	
	public FragmentManager fragmentManager;
	
	public DaoSession daoSession;
	
	
	public ActionCommentaryDao actionCommentaryDao;
	public BattingSummaryDao battingSummaryDao;
	public BowlingSummaryDao bowlingSummaryDao;
	public ExtrasSummaryDao extrasSummaryDao;
	public MatchDetailsDao matchDetailsDao;
	public MatchesDao matchesDao;
	public MatchInningsDao matchInningsDao;
	public MatchResultsDao matchResultsDao;
	public PlayerDao playerDao;
	public ScoreLineDao scoreLineDao;
	public ScoringTemplatesDao scoringTemplatesDao;
	public SubscriptionsDao subscriptionsDao;
	 
	
	
	public String matchID="";
	public boolean isEdit=false;
	 @Override
		public View onCreateView(LayoutInflater inflater, ViewGroup container,
				Bundle savedInstanceState) {
			// TODO Auto-generated method stub
			 
		 context = inflater.getContext();
		
		
			return super.onCreateView(inflater, container, savedInstanceState);
		}
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		
		
		
		
		
		resources=getResources();
		fragmentManager=getActivity().getSupportFragmentManager();
		
		daoSession=DbManager.getDbManager(getActivity());
		
		
		
		actionCommentaryDao=daoSession.getActionCommentaryDao();
		battingSummaryDao=daoSession.getBattingSummaryDao();
		bowlingSummaryDao=daoSession.getBowlingSummaryDao();
		extrasSummaryDao=daoSession.getExtrasSummaryDao();
		matchDetailsDao=daoSession.getMatchDetailsDao();
		matchesDao=daoSession.getMatchesDao();
		matchInningsDao=daoSession.getMatchInningsDao();
		matchResultsDao=daoSession.getMatchResultsDao();
		playerDao=daoSession.getPlayerDao();
		scoreLineDao=daoSession.getScoreLineDao();
		scoringTemplatesDao=daoSession.getScoringTemplatesDao();
		subscriptionsDao=daoSession.getSubscriptionsDao();
		
		super.onCreate(savedInstanceState);
		
	}

	
    


	public void setHeaderIntialize(View  v) {
		
		btnLeft=(Button)v.findViewById(R.id.leftIcon);
		btnRight=(Button)v.findViewById(R.id.rightIcon);
		title=(TextView)v.findViewById(R.id.title);
		
		
	}
	
	
	public void setHeaderTitle(String titleContent,int txtColor) {
		
		title.setText(titleContent);
		title.setTextColor(txtColor);
	}
	

	public void setHeaderImg(int imgContent) {
		
		title.setBackgroundResource(imgContent);
		
	}


	 
	public void setLeftReturn() {
		
			
		btnLeft.setCompoundDrawablesWithIntrinsicBounds( getResources().getDrawable(R.drawable.arrow_blue),null, null, null);
	
	}
	
	public void setLeftTextSelector(int normalColor,int pressColor,String textString) {
		btnLeft.setVisibility(View.VISIBLE);
			
		
		btnLeft.setTextColor(SelectorManager.getTextColor(normalColor, pressColor));
		btnLeft.setBackgroundColor(context.getResources().getColor(R.color.transparent));
		btnLeft.setText(textString);
	}
	
	public void setRightTextSelector(int normalColor,int pressColor,String textString) {
		btnRight.setVisibility(View.VISIBLE);	
		
		btnRight.setTextColor(SelectorManager.getTextColor(normalColor, pressColor));
		btnRight.setBackgroundColor(context.getResources().getColor(R.color.transparent));
		btnRight.setText(textString);
	}
	
	

	public void setLeftSelector(int normal,int press) {
		btnLeft.setVisibility(View.VISIBLE);
			
		SelectorManager.setBackground(btnLeft, SelectorManager.getButtonDrawableImage(getActivity(), normal, press));
		
	}
	
	public void setRightSelector(int normal,int press) {
		btnRight.setVisibility(View.VISIBLE);	
		SelectorManager.setBackground(btnRight, SelectorManager.getButtonDrawableImage(getActivity(), normal, press));
	}

	
	public Button getBtnLeft() {
		
		
		return btnLeft;
	}
	
	
	public Button getBtnRight() {
		return btnRight;
	}
	
	public TextView getTitle() {
		return title;
	}
	
	
	public void startBaseActivity(Intent i){
		
		
		this.startActivity(i);
		getActivity().overridePendingTransition(R.anim.push_left_in,R.anim.push_left_out);
	}
	
	

	
	public void changeFragment(Fragment newFragment,String fragmentName) {
		
		
		try{
		
		InputMethodManager imm = (InputMethodManager)   getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
				imm.hideSoftInputFromWindow(getActivity().getCurrentFocus().getWindowToken(), 0);
		}catch(Exception e){
			
		}
				
		FragmentTransaction transaction = getActivity().getSupportFragmentManager().beginTransaction();
		
		transaction.replace(R.id.relative_content, newFragment,fragmentName);
		transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
		transaction.addToBackStack(fragmentName);
		//transaction.commitAllowingStateLoss();
		
		transaction.commit();
		
		
	}
    
	

}
